package com.taobao.classloader.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taobao.classloader.ClassLoadStrategy;
import com.taobao.classloader.JarClassLoader;

public class ParentPriorLoadStrategy implements ClassLoadStrategy {
	private static Logger	logger	= LoggerFactory.getLogger(ParentPriorLoadStrategy.class);

	@Override
	public Class<?> loadClass(String className, JarClassLoader jarClassLoader, ClassLoader parentClassLoader) {
		Class<?> clazz;
		try {
			clazz = parentClassLoader.loadClass(className);
		} catch (ClassNotFoundException e) {
			logger.debug("Can't load class:{} from parent classLoader.", className);
			clazz = jarClassLoader.loadClassFromResource(className);
		}
		return clazz;
	}

	@Override
	public String toString() {
		return "ParentPriorLoadStrategy";
	}

}
